﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Text.RegularExpressions;

namespace RssBar
{
    /// <summary>
    /// Interaction logic for ucOptionsChannel.xaml
    /// </summary>
    public partial class ucOptionsChannel : UserControl, IOptionsContentPage
    {
        public ucOptionsChannel()
        {
            InitializeComponent();

            tbURL.Text = Configuration.ChannelAddress;
        }

        public string TitleText
        {
            get { return "Kanał Rss"; }
        }

        public bool Apply()
        {
            string pattern = @"^(http)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~])*[^\.\,\)\(\s]$";
            Regex reg = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
            if (reg.IsMatch(tbURL.Text))
            {
                Configuration.ChannelAddress = tbURL.Text;

                return true;
            }
            else
            {
                MessageBox.Show("Adres URL jest niepoprawny!");
                return false;
            }
        }
    }
}
